package com.hongshan.wallet.core.wallet

import android.app.Application
import android.databinding.ObservableField
import android.graphics.Color
import android.view.View
import com.hongshan.wallet.base.MyViewModel
import com.hongshan.wallet.bean.MoneyRecordBean
import com.hongshan.wallet.format

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.home
 * @author   : zhangxx
 * @date     : 2019/3/28
 * @email    : qq957413212@hotmail.com
 * @desc     : //TODO
 */
class CommissionRecycleViewModel(application: Application) : MyViewModel(application) {
    val green = Color.parseColor("#47aa6b")
    val red = Color.parseColor("#ea4750")
    val type = ObservableField<String>("订单返佣")
    val status = ObservableField<String>()
    val showStatus = ObservableField(false)
    val time = ObservableField<String>("2019-02-08 08:00")
    val money = ObservableField<String>("+43.00")
    val color = ObservableField<Int>(green)
    val desc = View.OnClickListener {

    }

    fun setMoneyRecord(moneyRecord: MoneyRecordBean) {
        time.set(moneyRecord.create_time.format("yyyy-MM-dd HH:mm"))
        type.set(
            when (moneyRecord.type_details) {
                1 -> "订单收款"
                2 -> "充值"
                3 -> "提现"
                4 -> "佣金转入"
                5 -> "订单返佣"
                6 -> "粉丝分润"
                7 -> "转入余额"
                else -> null
            }
        )
        money.set((if (moneyRecord.type == 1) '+' else '-') + moneyRecord.money)
        color.set(if (moneyRecord.type == 1) red else green)
        status.set(
            when (moneyRecord.status) {
                0 -> "待审核"
                1 -> "提现中"
                2 -> "提现成功"
                3 -> "提现失败"
                else -> null
            }
        )
        showStatus.set(moneyRecord.status != null && moneyRecord.type_details == 3)
    }
}